package com.sayice.robotconflict.ui.screen

import android.content.res.Resources
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.sp

/**
 * 设计宽高比
 */
const val GAME_DESIGN_WH_RADIO = 2

/**
 * 设计高度 (横屏)
 */
const val GAME_DESIGN_HEIGHT = 1000

/**
 * 设计宽度 (横屏)
 */
const val GAME_DESIGN_WIDTH = GAME_DESIGN_WH_RADIO * GAME_DESIGN_HEIGHT

/**
 * 单位像素
 */
private val unitPixel =
    if (Resources.getSystem().displayMetrics.widthPixels.toFloat() / Resources.getSystem().displayMetrics.heightPixels > GAME_DESIGN_WH_RADIO) {
        Resources.getSystem().displayMetrics.heightPixels.toFloat() / GAME_DESIGN_HEIGHT
    } else {
        Resources.getSystem().displayMetrics.widthPixels.toFloat() / GAME_DESIGN_WIDTH
    }

/**
 * 单位 dp
 */
private val unitDp = unitPixel / Resources.getSystem().displayMetrics.density

/**
 * 单位 sp
 */
private val unitSp = unitPixel / Resources.getSystem().displayMetrics.scaledDensity


/**
 * 屏幕适配单位 (px)
 */
val Number.cpx
    get() = toFloat() * unitPixel

/**
 * 屏幕适配单位 (dp)
 */
val Number.cdp
    get() = Dp(toFloat() * unitDp)

/**
 * 屏幕适配单位 (sp)
 */
val Number.csp
    get() = (toFloat() * unitSp).sp



